#include "Plugin.h"

#pragma unmanaged
#include "OpenGLRender.h"
#pragma managed

namespace TFlex
{
	RenderPlugin::RenderPlugin(PluginFactory^ factory) 
		: Plugin(factory)
		, _render(nullptr)
	{

	}

	void RenderPlugin::OnInitialize()
	{
		Plugin::OnInitialize();
	}

	void RenderPlugin::OnExited()
	{
		if (_render)
			delete _render;
	}

	void RenderPlugin::OnCreateTools()
	{
		Plugin::OnCreateTools();
	}

	void RenderPlugin::OnCommand(CommandEventArgs^ args)
	{
		if (!args->Document)
			return;
	}

	void RenderPlugin::DocumentOpenEventHandler(DocumentEventArgs^ args)
	{
		args->Document->AttachPlugin(this);
	}

	void RenderPlugin::NewDocumentCreatedEventHandler(DocumentEventArgs^ args)
	{
		args->Document->AttachPlugin(this);
	}

	void TFlex::RenderPlugin::ViewCreatedEventHandler(ViewEventArgs^ args)
	{
		Model::Model3D::View3D^ view = dynamic_cast<Model::Model3D::View3D^>(args->View);
		if (view)
		{
			_render = new OpenGLRender;
			view->InsertRender((IntPtr)_render);
		}
	}

	void RenderPlugin::DocumentRegeneratedEventHandler(RegenerateDocumentEventArgs^ args)
	{
	}

	void RenderPlugin::ClosingDocumentEventHandler(DocumentEventArgs^ args)
	{
	}

	void RenderPlugin::OnIdle(Object^ sender, EventArgs^ e)
	{
	}
}